/**
 * 
 */
package com.googlecode.lohr.parser.combinators.matcher;


import com.googlecode.lohr.parser.combinators.MatchError;
import com.googlecode.lohr.parser.combinators.node.StringNode;

/**
 * Matches anything of the given length
 * @author ted stockwell
 */
public class AnyStringMatcher extends Matcher
{
	private int _length;

	public AnyStringMatcher(int length)
	{
		_length= length;
	}

	@Override
	public void match(MatchContext ctx, int start) 
	{
		String input= ctx.getInput();
		if (input.length()-start < _length) {
			ctx.matchError(this, start, new MatchError("Expected input of length "+_length, start));
		}
		else {
			ctx.matchFound(this, start, new StringNode(this, start, start+_length, input.substring(start, start+_length)));
		}
		ctx.matchComplete(this, start);
	}
}